/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.editparts;

import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.editpolicies.DirectEditPolicy;

import edu.pku.sei.modeler.editpolicies.UMLDiagramGraphicalNodeEditPolicy;
import edu.pku.sei.modeler.figures.DecisionNodeFigure;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.structure.MetaShapeElement;
import edu.pku.sei.modeler.model.uml.IntermediateActivities.DecisionNode;

/**
 * @generated
 *
 */
public class DecisionNodeEditpart extends AbstractUMLNodeEditPart
{
	public DecisionNodeEditpart (MetaShapeElement model) {
		super(model);
	}
	/* (non-Javadoc)
	 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
	 */
	protected IFigure createFigure() {
//		Label header = new Label("GeneratedShape");
		DecisionNodeFigure figure = new DecisionNodeFigure();
//		figure.add(header);
		return figure;
	}

	protected DirectEditPolicy createDirectEditPolicy() {
//		return new DirectEditPolicy(){
//
//			@Override
//			protected Command getDirectEditCommand(DirectEditRequest arg0) {
//				return new ChangeNameCommand(getDecisionNode(), 
//						(String)arg0.getCellEditor().getValue());
//			}
//
//			@Override
//			protected void showCurrentEditValue(DirectEditRequest arg0) {
//				IFigure f = getDirectEditFigure();
//				if (f instanceof Label) {
//					((Label)f).setText(getDecisionNode().getName());
//				}
//			}
//			
//		};
		return null;
	}
	
	@Override
	protected IFigure getDirectEditFigure() {
//		return ((DecisionNodeFigure)this.getFigure()).getDecisionLable();
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
	 */
	protected void createEditPolicies() {
		super.createEditPolicies();
	}

	protected void handlePropertyChanged(PropertyChangeEvent event) {
		String propertyName = event.getPropertyName();
		super.handlePropertyChanged(event);
		refreshVisuals();
	}
	
	private DecisionNode getDecisionNode() {
		return (DecisionNode)((MetaNode)getModel()).getModelElement();
	}
	
	protected void refreshVisuals() {
		super.refreshVisuals();
		DecisionNode modelEle = (DecisionNode)getNode().getModelElement();
		DecisionNodeFigure figure = (DecisionNodeFigure)getFigure();
		
		
		figure.getDecisionLable().setText(""+modelEle.getName());
	}
}
